'''
编写一个程序，搜索指定目录（含其子目录）内的所有，txt文件，并找出其中最大的文件及其大小。

import os

result_files = []
search_dir = r"D:\pych"
for root, dirs, files in os.walk(search_dir):
    for file in files:
        if file.endswith(".txt"):
            file_path = f"{root}/{file}"
            file_size_kb = os.path.getsize(file_path) / 1024
result_files.append(file_path, file_size_kb)
sorted(result_files, key=lambda x: x[1], reverse=True)
'''


'''
从course_student_grade.txt文件中读取课程和学生成绩信息，计算并打印出每门课程的最高分、
最低分和平均分。

course_grades = {}
with open("course_student_grade.txt", "w", encoding="utf-8") as f:
    for line in f.readlines():
        line = line[:-1]
        course, sid, name, grade = line.split(",")
        if course not in course_grades:
           course_grades[course] = []

        course_grades[course].append(float(grade))
'''

'''
编写一个程序，从course_teacher.txt和course_student_grade.txt两个文本文件中读取信息，并
打印出包含课程名称、教师姓名、学生学号、学生姓名和学生成绩的完整信息。

course_teacher = {}
with open("course_teacher.txt", "r", encoding="utf-8") as f:
    for line in f.readlines():
        line = line[:-1]
        course, teacher = line.split(",")
        course_teacher[course] = teacher
with open("course_student_grade.txt", encoding="utf-8") as f:
    for line in f.readlines():
        line = line[:-1]
        course,sid, name ,grade = line.split(",")
        teacher = course_teacher.get(course)
        print(f"{course},{teacher},{name},{grade}")
'''

'''
编写一个程序，用于将指定目录下所有，txt文件的内容合并到一个新的文件中，每个文件的内容之
间使用换行符分隔。


import os

lst1 = []
date_dir = r"D:\pych"
for file in os.listdir(date_dir):
    file_path = f"{date_dir}/{file}"
    if os.path.isfile(file_path) and os.path.endswith(".txt"):
       with open(file_path, "r", encoding="utf-8") as f:
           lst1.append(f.read())
final_content = "\n\n".join(lst1)

with open("final_content.txt", "w", encoding="utf-8") as f:
    f.write(final_content)
'''

'''
从studentlike.txt文件中读取学生喜欢的项目列表，并统计各个项目的受欢迎程度（即被多少学生
喜欢）。

likes_dict = {}
with open("studentlike.txt", "r", encoding="utf-8") as f:
    for line in f.readlines():
        line = line[:-1]
        name, likes = line.split(" ")
        likes = likes.split(",")
        for like in likes_dict:
            if like not in likes_dict:
                likes_dict[like] = 1
            else:
                likes_dict[like] += 1

print(likes_dict)
'''